//
//  GetProductDetailViewController.m
//  HAODE
//
//  Created by panquanReabam.com on 15/9/19.
//  Copyright (c) 2015年 reabam.com. All rights reserved.
//

#import "BusinessCombinationDetailViewController.h"


#import "HttpRequest.h"
#import "JSONKit.h"
#import "ProductView.h"
#import "HAODEsingleton.h"
#import "UIButton+WebCache.h"
#import "shouyinCell.h"
#import "RDVTabBarController.h"
#import "ShopcatListViewController.h"
#import "TheLoginViewController.h"
#import "VPImageCropperViewController.h"
#import <AssetsLibrary/AssetsLibrary.h>
#import <MobileCoreServices/MobileCoreServices.h>
#import "UpYun.h"
#import "huiyuanDetailsCell.h"
#import "editorProductViewController.h"
#import "UMSocial.h"
#import "QRCodeGenerator.h"
#import "tItleVIew.h"
#define ORIGINAL_MAX_WIDTH 420.0f
@interface BusinessCombinationDetailViewController ()<UITableViewDataSource,UITableViewDelegate,UIScrollViewDelegate,UIWebViewDelegate, UITextViewDelegate,UIImagePickerControllerDelegate,UINavigationControllerDelegate,UIAlertViewDelegate,UIGestureRecognizerDelegate,UINavigationControllerDelegate,UIActionSheetDelegate,UMSocialUIDelegate>
@property (nonatomic, strong) UIImageView *portraitImageView;
@property (nonatomic,strong) UIImagePickerController *ipc;
@property (strong, nonatomic) UIImage *sendImage;
@property(nonatomic,retain)NSMutableArray* xuanxiang;
@property (retain, nonatomic) NSDictionary* dictionary;
@property(nonatomic,strong)   NSString*shareUrl;
@property (weak, nonatomic) UIPageControl * pageControl;
@property (nonatomic,retain)UIImageView* image1;
@property(nonatomic,strong)   NSString*shuoming;

@end

@implementation BusinessCombinationDetailViewController
{
    BOOL saveAccount;
    int requestState;
    int goodsPrice;
    UIImage *image;
    HAODEsingleton* commdity;
    UIWebView *webview;
    UIScrollView *myscrollView;
    UIScrollView *scrollView;
    UILabel *textlabel2;
    ProductView*clothView;
    UITableView *table_list;
     UIButton*bbuyBtn;
    
    UIButton*hejibuyBtn1;
    UIButton*idname1;
    NSMutableArray*currentSpecId;
    NSMutableArray*itemId;
    NSMutableArray*itemcode;
    NSMutableArray*itemName;
    NSMutableArray*how;
    NSMutableArray* specName;
    NSMutableArray* Price;
    NSMutableArray* imageUrlFull;
    NSMutableArray*minPrice;
    NSMutableArray*maxPrice;
    NSMutableArray*saleQty;
    NSMutableArray*hasSpec;
    NSMutableArray*salePrice;

}


@synthesize alt = alt;

-(void)BackAction:(UIButton *)sender{
    
    
    [self.navigationController popViewControllerAnimated:YES];
    
}

-(void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    
    [[UIApplication sharedApplication] setStatusBarHidden:TRUE];
    [[self rdv_tabBarController] setTabBarHidden:YES];
    
       UIImage* backImage = [UIImage imageNamed:@"fanhui"];
    CGRect backframe = CGRectMake(0,0,30,30);
    UIButton* backButton= [[UIButton alloc] initWithFrame:backframe];
    [backButton setBackgroundImage:backImage forState:UIControlStateNormal];
    backButton.titleLabel.font=[UIFont systemFontOfSize:13];
    [backButton addTarget:self action:@selector(BackAction:) forControlEvents:UIControlEventTouchUpInside];
    UIBarButtonItem* leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:backButton];
    self.navigationItem.leftBarButtonItem = leftBarButtonItem;
    
    [self.navigationController.navigationBar setBackgroundImage:[[UIImage alloc] init] forBarMetrics:UIBarMetricsDefault];
    self.navigationController.navigationBar.shadowImage =[[UIImage alloc] init];
    self.navigationController.navigationBarHidden=NO;
    self.navigationController.interactivePopGestureRecognizer.enabled = YES;
    self.navigationController.interactivePopGestureRecognizer.delegate = self;
    

    if ([commdity.gengxinxiangqing isEqualToString:@""]) {
        [myscrollView removeFromSuperview];
        [self add];
    }else{
  
    }
 
}



-(void)editor:(UIButton*)sender{
}
- (void)viewDidLoad {
    [super viewDidLoad];
    
    
    commdity=[HAODEsingleton shared];
    [self.navigationController.navigationBar setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:
                                                                     [UIColor blackColor],
                                                                     UITextAttributeTextColor,
                                                                     [UIColor colorWithRed:0.0 green:0.0 blue:0.0 alpha:1],
                                                                     UITextAttributeTextShadowColor,
                                                                     [NSValue valueWithUIOffset:UIOffsetMake(0, 0)],
                                                                     UITextAttributeTextShadowOffset,
                                                                     [UIFont fontWithName:@"Helvetica Neue" size:tetlefot],
                                                                     UITextAttributeFont,nil]];
    
    
    UIButton*editor1 = [[UIButton alloc] initWithFrame:CGRectMake(30, 0.0, 30, 30)];
    [editor1 setImage:[UIImage imageNamed:@"bianji"] forState:UIControlStateNormal];
    [editor1 addTarget:self action:@selector(editor:) forControlEvents:UIControlEventTouchUpInside];
    
    UIBarButtonItem* myBtnBtn1 = [[UIBarButtonItem alloc] initWithCustomView:editor1];
    
    NSArray *buttonArray = [[NSArray alloc]initWithObjects:myBtnBtn1, nil];
    self.navigationItem.rightBarButtonItems = buttonArray;

    
}


-(void )add{
    
    currentSpecId=[[NSMutableArray alloc]init];
    itemId=[[NSMutableArray alloc]init];
    itemcode=[[NSMutableArray alloc]init];
    itemName=[[NSMutableArray alloc]init];
    how=[[NSMutableArray alloc]init];
    Price=[[NSMutableArray alloc]init];
    imageUrlFull=[[NSMutableArray alloc]init];
    
    minPrice=[[NSMutableArray alloc]init];
    maxPrice=[[NSMutableArray alloc]init];
    saleQty=[[NSMutableArray alloc]init];
    hasSpec=[[NSMutableArray alloc]init];
    salePrice=[[NSMutableArray alloc]init];
    table_list = [[UITableView alloc]initWithFrame:CGRectMake(0, -64, ScreenWidth, ScreenHeight+20) style:UITableViewStylePlain];
    table_list.delegate = self;
    table_list.dataSource = self;
    table_list.separatorStyle=UITableViewCellSeparatorStyleNone;
    
    myscrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0,0, ScreenWidth, ScreenHeight)];
    myscrollView.delegate = self;
    myscrollView.userInteractionEnabled = YES;
    myscrollView.scrollEnabled = YES;
    myscrollView.showsVerticalScrollIndicator = FALSE;
    myscrollView.showsHorizontalScrollIndicator = FALSE;
  
                
    tItleVIew *view1 = [[tItleVIew alloc]initWithFrame:CGRectMake(0, 0, ScreenWidth, 220)];

    NSMutableArray *array = [NSMutableArray arrayWithCapacity:[self.imageListArray count]];
                        
    for (NSDictionary *dic in self.imageListArray) {
                            [array addObject:[dic objectForKey:@"imageUrlFull"]];
                           
                        }
                        
        view1.arrayImage = array;
    [myscrollView addSubview:view1];
    
    UILabel* titleStr = [[UILabel alloc]initWithFrame:CGRectMake(15, view1.bottom+20, 260, 17)];
    titleStr.textColor = [UIColor blackColor];
    titleStr.text=[NSString stringWithFormat:@"%@",self.titleStr];
    titleStr.font = [UIFont systemFontOfSize:17];
    [myscrollView addSubview:titleStr];
   
    NSString *s1 =[NSString stringWithFormat:@"%@", self.detailStr];
    UIFont *font1 = [UIFont systemFontOfSize:14];
    CGSize size1 = CGSizeMake(ScreenWidth-60, 2000);
    CGSize labelsize1 = [s1 sizeWithFont:font1 constrainedToSize:size1 lineBreakMode:NSLineBreakByCharWrapping];
    
    UILabel*detail = [[UILabel alloc]initWithFrame:CGRectMake(15, titleStr.bottom+10, ScreenWidth-30, labelsize1.height)];
    detail.textColor = zhonghuiColor;
    detail.numberOfLines=0;
    detail.text=[NSString stringWithFormat:@"%@",self.detailStr];
    detail.font = [UIFont systemFontOfSize:14];
    [myscrollView addSubview:detail];

    UIView*view=[[UIView alloc]initWithFrame:CGRectMake(0, detail.bottom+20, ScreenWidth, 10)];
    view.backgroundColor=zuiqianhuicolor;
    view.layer.borderWidth = 0.35;
    view.layer.borderColor = qianhuicolor.CGColor;
    [myscrollView addSubview:view];
    
    UILabel* dapei = [[UILabel alloc]initWithFrame:CGRectMake(0, view.bottom, ScreenWidth, 44)];
    dapei.textColor = [UIColor blackColor];
    dapei.text=[NSString stringWithFormat:@"%@",@"搭配商品"];
    dapei.textAlignment=NSTextAlignmentCenter;
    dapei.font = [UIFont systemFontOfSize:15];
    [myscrollView addSubview:dapei];
 
    
    UILabel*line=[[UILabel alloc]initWithFrame:CGRectMake(10, dapei.bottom, ScreenWidth-30, 0.35)];
    line.backgroundColor=qianhuicolor;
    [myscrollView addSubview:line];
    myscrollView.frame=CGRectMake(0, 0, ScreenWidth, line.bottom);
 
    table_list.tableHeaderView=myscrollView;
    [self.view addSubview:table_list];
  
   //加载搭配商品／／／／／／／／／／／／／／／／／／／／／／／／／／

    NSUserDefaults *user = [NSUserDefaults standardUserDefaults];
    NSString* Token = [user objectForKey:@"tokenId"];
    if (Token ==nil) {
        Token=@"dd";
    }
    NSMutableDictionary *param = [NSMutableDictionary new];
    [param setValue:Token forKey:@"tokenId"];
    [param setValue:self.cbIdStr forKey:@"cbId"];
   // NSLog(@"====%@",param);
    [Global showIndeterminateHudSub:@"加载中，请稍后。。。" delay:30 view:self.view];
    [HttpRequest requestData:@"Business/Combination/ItemList" params:param success:^(BOOL isSuccess, SeverData *severDataDict) {
        if (isSuccess) {
            
          //  NSLog(@"====－－－－－－－%@",severDataDict.dataDict);
            
            
            if ([[severDataDict.dataDict objectForKey:@"ResultInt"] integerValue]==0) {
                [Global hideProgressHUDInternal:self.view];
                
                NSMutableArray* arrr=[[NSMutableArray alloc]init];
                
                arrr=[severDataDict.dataDict objectForKey:@"DataLine"];
                
                for (NSDictionary* dicc in arrr )
                {
                    [itemId addObject:[dicc valueForKey:@"itemId"]];
                    [itemName addObject:[dicc valueForKey:@"itemName"]];
                    [imageUrlFull addObject:[dicc valueForKey:@"imageUrlFull"]];
                    [salePrice addObject:[dicc valueForKey:@"salePrice"]];
                    [hasSpec addObject:[dicc valueForKey:@"hasSpec"]];
                    [saleQty addObject:[dicc valueForKey:@"saleQty"]];
                    [maxPrice addObject:[dicc valueForKey:@"maxPrice"]];
                    [minPrice addObject:[dicc valueForKey:@"minPrice"]];
                    
                    [how addObject:@"0"];
                }
                
                [table_list reloadData];
                
            }else{
                [Global hideProgressHUDInternal:self.view];
                NSString *requestResultStr=[severDataDict.dataDict objectForKey:@"ResultString"];
                [Global showTextHudSub:requestResultStr view:self.view];
            }
            
        }
        else
        {
            [Global hideProgressHUDInternal:self.view];
            
            [Global showTextHudSub:@"连接失败" view:self.view];
        }
        
    }];


    
    bbuyBtn=[[UIButton alloc]initWithFrame:CGRectMake(0, ScreenHeight-45, ScreenWidth*430/750, 45)];
  
    bbuyBtn.backgroundColor=backColor;
    bbuyBtn.alpha=0.8;
    [self.view addSubview:bbuyBtn];

    UIButton*Btn=[[UIButton alloc]initWithFrame:CGRectMake(0, ScreenHeight-45, ScreenWidth*430/750, 45)];
    Btn.backgroundColor=[UIColor clearColor];
    [self.view addSubview:Btn];
    
    UIButton*buyBtn1=[[UIButton alloc]initWithFrame:CGRectMake(10, 5, ScreenWidth*60/750, ScreenWidth*60/750)];
    [buyBtn1 setImage:[UIImage imageNamed:@"gouwuchexiangqing"] forState:UIControlStateNormal];
    [Btn addSubview:buyBtn1];

    
   
    idname1 = [[UIButton alloc] initWithFrame:CGRectMake(70*ScreenWidth/750, 5, 20, 20)];
    idname1.backgroundColor=[UIColor colorWithRed:229.00/255.00 green:19/255.00 blue:19/255.00 alpha:1.0];
    [idname1 setTitle:[NSString stringWithFormat: @"%@",@""]forState:UIControlStateNormal];
    [idname1 setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    idname1 .titleLabel.font=[UIFont systemFontOfSize:14];
    idname1.layer.masksToBounds = YES;
    idname1.layer.cornerRadius = 10;
    idname1.layer.borderColor = [UIColor whiteColor].CGColor;
    idname1.layer.borderWidth = 0;
    idname1.titleLabel.textAlignment = NSTextAlignmentCenter;
    [Btn addSubview:idname1];

    
    hejibuyBtn1=[[UIButton alloc]initWithFrame:CGRectMake(buyBtn1.right+20, ScreenHeight-45, ScreenWidth*430/750, 45)];
    [hejibuyBtn1 setTitle:[NSString stringWithFormat:@"合计 ¥ %@",@""] forState:UIControlStateNormal];
    hejibuyBtn1.contentHorizontalAlignment=UIControlContentHorizontalAlignmentLeft;
    [hejibuyBtn1 setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [self.view addSubview:hejibuyBtn1];

    UILabel*line1=[[UILabel alloc]initWithFrame:CGRectMake(0, ScreenHeight-45, ScreenWidth, 0.40)];
    line1.backgroundColor=LineColor;
    [self.view addSubview:line1];
    
    UIButton*buyBtn11=[[UIButton alloc]initWithFrame:CGRectMake(ScreenWidth*430/750, ScreenHeight-45, ScreenWidth*320/750, 45)];
    [buyBtn11 setTitle:@"确认订单" forState:UIControlStateNormal];
    buyBtn11.backgroundColor=luseColor;
    [buyBtn11 setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    
//    [buyBtn11 addTarget:self action:@selector(addcat:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:buyBtn11];

    
    
    
    
    
}

#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}



- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return [itemId count];
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"Cell";
    
    huiyuanDetailsCell* cell = (huiyuanDetailsCell*)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil)
    {
        NSArray* nib = [[NSBundle mainBundle] loadNibNamed:@"huiyuanDetailsCell" owner:self options:nil];
        cell = [nib objectAtIndex:0];
    }
    UIButton*jiantou = [[UIButton alloc]init];
    jiantou.frame = CGRectMake(0,0, 8, 13);
    [jiantou setImage:[UIImage imageNamed:@"xiangzuo-.png"] forState:UIControlStateNormal];
    
    //    cell.accessoryView = jiantou;
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    
    
    
    [cell.imagebtn.layer setCornerRadius:2.0];
    [cell.imagebtn.layer setBorderWidth:0.3];
    [cell.imagebtn.layer setMasksToBounds:YES];
    CGColorSpaceRef colorSpace2 = CGColorSpaceCreateDeviceRGB();
    CGColorRef colorref2 = CGColorCreate(colorSpace2,(CGFloat[]){ 0, 0, 0, 0.3 });
    [cell.imagebtn.layer setBorderColor:colorref2];//边框颜色
    [cell.imagebtn setImageWithURL:[NSURL URLWithString:[imageUrlFull objectAtIndex:indexPath.row]]];
    //    [cell.imagebtn setImageWithURL:[NSURL URLWithString:[ImageUrl objectAtIndex:indexPath.row]]placeholderImage:nil];
    cell.imagebtn.frame=CGRectMake(ScreenWidth*30/750,  ScreenHeight*40/1334,  ScreenWidth*170/750,  ScreenHeight*170/1334);
    
    
    
    cell.CreateDate.text =[NSString stringWithFormat:@"%@",[itemName objectAtIndex:indexPath.row]];
    cell.CreateDate.font=[UIFont systemFontOfSize:sixteenORfifteenFot];
    cell.CreateDate.textColor=[UIColor blackColor];
    cell.CreateDate.frame=CGRectMake(215*ScreenWidth/750, ScreenHeight*30/1334, 520*ScreenWidth/750,32);
    cell.CreateDate.numberOfLines=1;
    
    
    
   
    if ([[hasSpec objectAtIndex:indexPath.row]isEqualToString:@"Y"]) {
        NSString*GoldPrice=[NSString stringWithFormat:@"%@",[minPrice objectAtIndex:indexPath.row]];
        NSNumberFormatter *numberFormatter = [[NSNumberFormatter alloc] init];
        [numberFormatter setPositiveFormat:@"###,##0.00;"];
        NSString *formattedNumberString = [numberFormatter stringFromNumber:[NSNumber numberWithDouble:GoldPrice.floatValue]];
        
        NSString*GoldPrice1=[NSString stringWithFormat:@"%@",[maxPrice objectAtIndex:indexPath.row]];
        NSNumberFormatter *numberFormatter1 = [[NSNumberFormatter alloc] init];
        [numberFormatter1 setPositiveFormat:@"###,##0.00;"];
        NSString *formattedNumberString1 = [numberFormatter1 stringFromNumber:[NSNumber numberWithDouble:GoldPrice1.floatValue]];
        
        
        cell.Price.text =[NSString stringWithFormat:@"￥%@~%@",  formattedNumberString,formattedNumberString1];
        cell.Price.font=[UIFont systemFontOfSize:18];
        cell.Price.textColor=hongsecolor;
        cell.Price.frame=CGRectMake(215*ScreenWidth/750, 50, 400*ScreenWidth/750,19);
        NSMutableAttributedString *AttributedStr2 = [[NSMutableAttributedString alloc]initWithString:[NSString stringWithFormat:@"￥%@~%@",  formattedNumberString,formattedNumberString1]];
        [AttributedStr2 addAttribute:NSFontAttributeName
         
                               value:[UIFont systemFontOfSize:14.0]
         
                               range:NSMakeRange(0, 1)];
        
        [AttributedStr2 addAttribute:NSForegroundColorAttributeName
         
                               value:hongsecolor
         
                               range:NSMakeRange(0, 1)];
        
        cell.Price.attributedText = AttributedStr2;

    }else{
    
  
    NSString*GoldPrice=[NSString stringWithFormat:@"%@",[salePrice objectAtIndex:indexPath.row]];
    NSNumberFormatter *numberFormatter = [[NSNumberFormatter alloc] init];
    [numberFormatter setPositiveFormat:@"###,##0.00;"];
    NSString *formattedNumberString = [numberFormatter stringFromNumber:[NSNumber numberWithDouble:GoldPrice.floatValue]];
    
    cell.Price.text =[NSString stringWithFormat:@"￥%@",  formattedNumberString];
    cell.Price.font=[UIFont systemFontOfSize:18];
    cell.Price.textColor=hongsecolor;
    cell.Price.frame=CGRectMake(215*ScreenWidth/750, 50, 400*ScreenWidth/750,19);
    NSMutableAttributedString *AttributedStr2 = [[NSMutableAttributedString alloc]initWithString:[NSString stringWithFormat:@"￥%@",  formattedNumberString]];
    
    [AttributedStr2 addAttribute:NSFontAttributeName
     
                           value:[UIFont systemFontOfSize:14.0]
     
                           range:NSMakeRange(0, 1)];
    
    [AttributedStr2 addAttribute:NSForegroundColorAttributeName
     
                           value:hongsecolor
     
                           range:NSMakeRange(0, 1)];
    
    cell.Price.attributedText = AttributedStr2;
    }
    cell.Memo.text =[NSString stringWithFormat:@"销量 %@ 件",[saleQty objectAtIndex:indexPath.row]];
    cell.Memo.font=[UIFont systemFontOfSize:14];
    cell.Memo.textColor=shenhuicolor;
    cell.Memo.frame=CGRectMake(215*ScreenWidth/750, cell.Price.bottom+5, 520*ScreenWidth/750,32);
    
    UIImageView*shuimageview=[[UIImageView alloc]initWithFrame:CGRectMake(ScreenWidth-140, 75, 120, 30)];
    shuimageview .image=[UIImage imageNamed:@"tianjias"];
    [cell.contentView addSubview:shuimageview];
    
    //cell.time=[[UILabel alloc]initWithFrame:CGRectMake(0, 0, 120, 30)];
    cell.time.text=[NSString stringWithFormat:@"%@",  [how objectAtIndex:indexPath.row]];
    cell.time.textColor=[UIColor blackColor];
    cell.time.center=shuimageview.center;
    cell.time.textAlignment=NSTextAlignmentCenter;
    cell.time.font=[UIFont systemFontOfSize:15];
    [cell.contentView addSubview:cell.time];
    cell.how=[NSString stringWithFormat:@"%@",  [how objectAtIndex:indexPath.row]];
    UIButton*jian=[[UIButton alloc]initWithFrame:CGRectMake(ScreenWidth-140, 75, 30, 30)];
    jian.tag=indexPath.row;
    [jian addTarget:self action:@selector(jian:) forControlEvents:UIControlEventTouchUpInside];
    [cell.contentView addSubview:jian];
    
    UIButton*jia=[[UIButton alloc]initWithFrame:CGRectMake(ScreenWidth-50,75, 30, 30)];
    jia.tag=indexPath.row;
    [jia addTarget:self action:@selector(jia:) forControlEvents:UIControlEventTouchUpInside];
    [cell.contentView addSubview:jia];
    
    
    
    
    if (itemId.count !=indexPath.row+1) {
        UILabel *lineLabel11=[[UILabel alloc] initWithFrame:CGRectMake(15, 245*ScreenHeight/1334-0.35, ScreenWidth-30, 0.35)];
        lineLabel11.backgroundColor=[UIColor groupTableViewBackgroundColor];;
        [cell.contentView addSubview:lineLabel11];
        
    }
    
    if (itemId.count ==indexPath.row+1) {
        UILabel *lineLabel11=[[UILabel alloc] initWithFrame:CGRectMake(0, 245*ScreenHeight/1334-0.35, ScreenWidth, 0.35)];
        lineLabel11.backgroundColor=[UIColor groupTableViewBackgroundColor];
        [cell.contentView addSubview:lineLabel11];
        
    }
    
    return cell;
}

- (CGFloat) tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    
    return  245*ScreenHeight/1334;
}

#pragma mark - Table view delegate



- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    
    
    
    
    
    
}

-(void)jia:(UIButton*)sender{
    
    UIButton* button=(UIButton * )sender;
    huiyuanDetailsCell* cell=(huiyuanDetailsCell* )button.superview.superview;
    
    int d;
    d= cell.time.text.intValue;
    d++;
   // NSLog(@"---------%ld",sender.tag);
    
    
    NSMutableArray *mutableArray = [NSMutableArray arrayWithArray:how];
    [mutableArray replaceObjectAtIndex:sender.tag withObject:[NSString stringWithFormat:@"%d", d]];
    how = mutableArray;//now the array has been "updated"
    commdity.how44=[how mutableCopy];
    cell.time.text=[NSString stringWithFormat:@"%d", d];
    
    [self heji];
}
-(void)heji{
   
    
    NSMutableArray*  sum=[[NSMutableArray alloc]init];
    
    for (int i=0; i<Price.count; i++) {
        
        NSString *typeCode1 = [Price objectAtIndex:i];
        NSString *isSingle1 = [how objectAtIndex:i];
        
        [sum addObject:[NSString stringWithFormat:@"%.2f",  [typeCode1 doubleValue]*[isSingle1 doubleValue]]];
        
        
    }
    
    NSNumber *sum11 = [sum valueForKeyPath:@"@sum.floatValue"];
    NSString*GoldPrice=[NSString stringWithFormat:@"%@",sum11];
    NSNumberFormatter *numberFormatter = [[NSNumberFormatter alloc] init];
    [numberFormatter setPositiveFormat:@"###,##0.00;"];
    NSString *formattedNumberString = [numberFormatter stringFromNumber:[NSNumber numberWithDouble:GoldPrice.floatValue]];
    [hejibuyBtn1 setTitle:[NSString stringWithFormat:@"合计 ¥ %@",formattedNumberString] forState:UIControlStateNormal];
   
    NSNumber *sum1 = [how valueForKeyPath:@"@sum.floatValue"];
    NSString*shu=[NSString stringWithFormat:@"%@",sum1];
    [idname1 setTitle:[NSString stringWithFormat: @"%@",shu]forState:UIControlStateNormal];

   
}

-(void)jian:(UIButton*)sender{
    
    UIButton* button=(UIButton * )sender;
    huiyuanDetailsCell* cell=(huiyuanDetailsCell* )button.superview.superview;
    
    if ([cell.time.text isEqualToString:@"0"]) {
        [self showAlertMessage:@"数量不能为负数！"];
        
        
    }else{
        
        int d;
        d= cell.time.text.intValue;
        d--;
        NSLog(@"---------%ld",sender.tag);
        
        
        NSMutableArray *mutableArray = [NSMutableArray arrayWithArray:how];
        [mutableArray replaceObjectAtIndex:sender.tag withObject:[NSString stringWithFormat:@"%d", d]];
        how = mutableArray;//now the array has been "updated"
        commdity.how44=[how mutableCopy];
        cell.time.text=[NSString stringWithFormat:@"%d", d];
        
        [self heji];
    }
    
    
}



-(void)queren{
    
    
    
    
    
    
    
    
    
    
}
- (UIViewController *)appRootViewController
{
    UIViewController *appRootVC = [UIApplication sharedApplication].keyWindow.rootViewController;
    UIViewController *topVC = appRootVC;
    while (topVC.presentedViewController) {
        topVC = topVC.presentedViewController;
    }
    return topVC;
}

- (void)tapAction {
    UIScrollView *scroll = [[UIScrollView alloc]initWithFrame:CGRectMake(0, 0, ScreenWidth, ScreenHeight)];
    scroll.backgroundColor = [UIColor blackColor];
    [[self appRootViewController].view addSubview:scroll];
    
    UIImageView *imagev = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, ScreenWidth,ScreenWidth*image.size.height/image.size.width)];
    imagev.image = image;
    if (imagev.frame.size.height < ScreenHeight) {
        imagev.center = scroll.center;
    }
    
    [scroll addSubview:imagev];
    scroll.contentSize = CGSizeMake(ScreenWidth, imagev.frame.size.height);
    
    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tapAction2)];
    [scroll addGestureRecognizer:tap];
    scroll.tag = 100;
}

- (void)tapAction2 {
    UIScrollView *scroll = (UIScrollView *)[[self appRootViewController].view viewWithTag:100];
    [scroll removeFromSuperview];
}


- (void)showAlertWait
{
    alt = [[UIAlertView alloc] initWithTitle:@"网络不稳定 ！" message:@"请确认网络" delegate:self cancelButtonTitle:nil otherButtonTitles: nil];
    [alt show];
    
    [self performSelector:@selector(hideAlert) withObject:nil afterDelay:1.0f];
    
}

- (void)showAlertMessage:(NSString *)msg
{
    alt = [[UIAlertView alloc] initWithTitle:@"温馨提示" message:msg delegate:nil cancelButtonTitle:nil otherButtonTitles: nil];
    [alt show];
    
    [self performSelector:@selector(hideAlert) withObject:nil afterDelay:1.0f];
}
- (void)hideAlert
{
    if (alt != nil)
    {
        [alt dismissWithClickedButtonIndex:0 animated:YES];
        alt = nil;
    }
}


@end
